package main

import (
	"heartbeat/controller"
	_init "heartbeat/init"
	"heartbeat/utils"
	"time"

	"log"

	iris "gopkg.in/kataras/iris.v6"
	"gopkg.in/kataras/iris.v6/adaptors/httprouter"
	"gopkg.in/kataras/iris.v6/adaptors/sessions"
)

func main() {
	if true != _init.InitEnv() {
		time.Sleep(3 * time.Second)
		return
	}
	go func() {
		for range time.Tick(time.Minute * 5) {
			//AlarmByEmail()
		}
	}()

	config := utils.GetConfig().Other

	app := iris.New()
	sessionAdapt := sessions.New(sessions.Config{})

	app.Adapt(
		httprouter.New(),
		sessionAdapt)

	API := app.Party("/api", controller.AuthCtrl)
	API.Post("/login", controller.LoginPost)
	API.Get("/heartbeat", controller.HeartbeatCtr.Get)
	API.Get("/badlist", controller.HeartbeatCtr.GetBadList)
	API.Delete("/bad/:id", controller.HeartbeatCtr.Delete)
	app.StaticWeb("/static", config["static"])
	log.Println("服务器运行于端口" + config["port"])
	app.Listen(config["port"])

}
